#include  <cstdio>
#include  <cstring>
#include  <cstdlib>
#include  <algorithm>
#include  <functional>
using namespace std;

int main(int argc, char *argv[])
{
	int n;
	scanf("%d",&n);

	while( n!=-1 )
	{
		char ss[100];
		sprintf(ss,"%d",n);
		printf("N=%d:\n",n);
		if(ss[0] == ss[1] && ss[1]== ss[2] &&
				ss[2] == ss[3] || strlen(ss) != 4 )
		{
			printf("No!!\n");
			scanf("%d",&n);
			continue;

		}

		int big,small,counter = 0,diff;
		while( true )
		{
			sort(ss,ss+strlen(ss),greater<char>());
			big = atoi(ss);
			sort(ss,ss+strlen(ss),less<char>());
			small = atoi(ss);
			diff = big - small;
			counter++;
			printf("%d-%d=%d\n",big,small,diff);
			if( diff == 6174 || diff == 0 )
			{
				printf("Ok!! %d times\n",counter);
				break;
			}
			sprintf(ss,"%d",diff);
		}

		scanf("%d",&n);
	}
}
